import os, sys
from PIL import Image

#size = (128,128)
size = (1024,1024)
for infile in sys.argv[1:]:
    outfile = os.path.splitext(infile)[0]+".thumbnail"
    if infile != outfile:
        try:
            im = Image.open(infile)
            im.thumbnail(size)
            im.save(outfile,"JPEG")
        except IOError:
            print("Cannot create trumbnail for", infile)
